<script setup lang="ts">
import FyiModal from '../FyiModal'
import { ref } from 'vue'
import { locales, handleSetLanguage } from '@/i18n'
const handleGo = (arg) => {
  currentUseLocale.value = arg
  handleSetLanguage(arg)
}
const currentUseLocale = ref('en-US')
const init = () => {
  currentUseLocale.value = localStorage.lang
}
init()
const show = ref(false)
</script>
<template>
  <div class="locale-selector-handle" @click="show = true">
    <ap-icon name="global" :size="14" /> {{ $t('locale.current') }}
  </div>
  <fyi-modal v-model="show">
    <div class="language-selector-title">{{ $t('locale.select') }}</div>
    <div class="language-container">
      <div :class="['locale-item', currentUseLocale === key ? 'locale-item-active' : '']" v-for="item,key in locales" @click="handleGo(key)">
        <div class="locale-item-title">{{ item.name }}</div>
        <div class="locale-item-desc">
          <span v-for="flag in item.flags">{{ flag }}</span>
        </div>
      </div>
    </div>
  </fyi-modal>
</template>

<style lang="less" scoped>
.locale-selector-container {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}
.language-selector-title {
  
}
.language-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  .locale-item {
    .locale-item-title {
      font-weight: bold;
    }
  }
  .locale-item-active {
    border-color: #4C9EEA!important;
  }
}

// Mobile
@media screen and (max-width: 767px) {
  .locale-selector-handle {
    font-size: 14px;
    justify-content: flex-end;
  }
  .language-selector-title {
    font-size: 24px;
  }
  .language-container {
    margin-top: 40px;
    margin-bottom: 40px;
    gap: 10px;
    .locale-item {
      cursor: pointer;
      width: 100%;
      border: 1px solid #EDEDED;
      padding: 15px;
      border-radius: 20px;
      .locale-item-title {
        font-size: 14px;
      }
      .locale-item-desc {
        font-size: 12px;
        margin-top: 5px;
      }
    }
  }
}

// Tablet
@media screen and (max-width: 1023px) and (min-width: 768px) {
  .locale-selector-handle {
    font-size: 14px;
    justify-content: flex-end;
  }
  .language-selector-title {
    font-size: 24px;
  }
  .language-container {
    margin-top: 40px;
    margin-bottom: 40px;
    gap: 10px;
    .locale-item {
      width: calc(50% - 10px);
      border: 1px solid #EDEDED;
      padding: 15px;
      border-radius: 20px;
      .locale-item-title {
        font-size: 14px;
      }
      .locale-item-desc {
        font-size: 12px;
        margin-top: 5px;
      }
    }
  }
}

// Desktop
@media screen and (min-width: 1024px) {
  .locale-selector-handle {
    font-size: 14Px;
    cursor: pointer;
    justify-content: flex-end;
  }
  .language-selector-title {
    font-size: 24Px;
  }
  .language-container {
    margin-top: 40Px;
    margin-bottom: 40Px;
    gap: 10Px;
    .locale-item {
      cursor: pointer;
      width: calc(50% - 10Px);
      border: 1Px solid #EDEDED;
      padding: 15Px;
      border-radius: 20Px;
      .locale-item-title {
        font-size: 14Px;
      }
      .locale-item-desc {
        font-size: 12Px;
        margin-top: 5Px;
      }
    }
  }
}
</style>